default_platform(:ios)

platform :ios do

  desc "Build React Native Sample"
  lane :build_react_native_sample do
    setup_ci

    sync_code_signing(
      type: "appstore",
      readonly: true,
      app_identifier: ["io.sentry.reactnative.sample"]
    )

    build_app(
      workspace: "ios/sentryreactnativesample.xcworkspace",
      scheme: "sentryreactnativesample",
      configuration: "Release",
      include_bitcode: false,
      include_symbols: true,
      export_method: "app-store",
      archive_path: "sentryreactnativesample"
    )

    delete_keychain(name: "fastlane_tmp_keychain") unless is_ci
  end

  desc "Upload React Native Sample to TestFlight"
  lane :upload_react_native_sample_to_testflight do

    app_store_connect_api_key(
      key_id: ENV["APP_STORE_CONNECT_KEY_ID"],
      issuer_id: ENV["APP_STORE_CONNECT_ISSUER_ID"],
      key_content: ENV["APP_STORE_CONNECT_KEY"]
    )

    testflight(
      skip_waiting_for_build_processing: true,
    )
  end


  desc "Generate all provisioning profiles for development"
  lane :setup_code_signing do
    app_identifiers = [
      "io.sentry.reactnative.sample"
    ]
    sync_code_signing(
      type: "development",
      app_identifier: app_identifiers,
      readonly: false
    )
    sync_code_signing(
      type: "appstore",
      app_identifier: app_identifiers,
      readonly: false
    )
  end
end
